/*
 * Copyright 2015-2016 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * You may not use this file except in compliance with the terms and conditions set forth
 * in the accompanying LICENSE.TXT file.
 *
 * THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS.  AMAZON SPECIFICALLY DISCLAIMS, WITH
 * RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
 */

package com.amazon.alexa.voicechrome.internal.views;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.LinearInterpolator;

import java.util.ArrayList;

/**
 * A view capable of animating entry and exit
 */
public class ChromeTransitionView extends TransitionView {
    private float defaultAlpha;
    private float newAlpha;

    public ChromeTransitionView(Context context) {
        super(context);
    }

    public ChromeTransitionView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ChromeTransitionView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected ArrayList<AnimatorSet> defineAnimators() {
        defaultAlpha = getAlpha();
        newAlpha = 1;

        ObjectAnimator oAlphaStart = ObjectAnimator.ofFloat(this, "alpha", newAlpha).setDuration(animationDuration);
        oAlphaStart.setInterpolator(new LinearInterpolator());

        AnimatorSet startAnimator = new AnimatorSet();
        startAnimator.playTogether( oAlphaStart);

        ObjectAnimator oAlphaStop = ObjectAnimator.ofFloat(this, "alpha", defaultAlpha).setDuration(animationDuration);

        AnimatorSet stopAnimator = new AnimatorSet();
        stopAnimator.playTogether( oAlphaStop);

        ArrayList<AnimatorSet> animators = new ArrayList<>();
        animators.add(startAnimator);
        animators.add(stopAnimator);
        return animators;
    }

    @Override
    protected void setToEnd() {
        setAlpha(newAlpha);
    }

    @Override
    protected void setToStart() {
        setAlpha(defaultAlpha);
    }
}